import numpy as np
import pandas as pd
from scipy.stats import pearsonr, spearmanr
# 数据
data = {
    '工作年限': [1, 2, 3, 4, 5],
    '工作满意度': [8, 7, 9, 6, 10],
    '年薪': [5, 7, 8, 11, 13]
}
df = pd.DataFrame(data)

# 皮尔逊相关系数
pearson_corr_salary_years, _ = pearsonr(df['工作年限'], df['年薪'])
pearson_corr_salary_satisfaction, _ = pearsonr(df['工作满意度'], df['年薪'])

# 斯皮尔曼相关系数
spearman_corr_salary_years, _ = spearmanr(df['工作年限'], df['年薪'])
spearman_corr_salary_satisfaction, _ = spearmanr(df['工作满意度'], df['年薪'])

# 输出结果
print(f"工作年限与年薪的皮尔逊相关系数: {pearson_corr_salary_years:.2f}")
print(f"工作满意度与年薪的皮尔逊相关系数: {pearson_corr_salary_satisfaction:.2f}")
print(f"工作年限与年薪的斯皮尔曼相关系数: {spearman_corr_salary_years:.2f}")
print(f"工作满意度与年薪的斯皮尔曼相关系数: {spearman_corr_salary_satisfaction:.2f}")